# PDF解密UI
from info import user_info_jiem
from PyQt5.QtCore import QRect
from PyQt5.QtWidgets import QLabel, QLineEdit, QPushButton, QMessageBox, QMainWindow, QFileDialog


class PDF_Decrypt_UI(QMainWindow):
    def setupUi(self):
        self.resize(550, 100)
        self.label = QLabel(self)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(9, 19, 132, 16))
        self.lineEdit = QLineEdit(self)
        self.lineEdit.setObjectName(u"lineEdit")
        self.lineEdit.setGeometry(QRect(147, 19, 201, 20))
        self.pushButton = QPushButton(self)
        self.pushButton.setObjectName(u"pushButton")
        self.pushButton.setGeometry(QRect(450, 20, 91, 51))
        self.pushButton.clicked.connect(self.pubshbutton_click)
        self.label_2 = QLabel(self)
        self.label_2.setObjectName(u"label_2")
        self.label_2.setGeometry(QRect(9, 55, 60, 16))
        self.lineEdit_2 = QLineEdit(self)
        self.lineEdit_2.setObjectName(u"lineEdit_2")
        self.lineEdit_2.setGeometry(QRect(147, 55, 201, 20))
        self.retranslateUi()
        self.Button2()

    def retranslateUi(self):
        self.setWindowTitle(user_info_jiem)
        self.label.setText("请选择需要解密软件")
        self.pushButton.setText("解密")
        self.label_2.setText("请输入密码")

    def Button2(self):
        button = QPushButton(self)
        button.setText("浏览文件")
        button.setGeometry(QRect(350, 20, 91, 51))
        button.clicked.connect(self.Button2_click)

    def Button2_click(self):
        file = QFileDialog.getOpenFileName(self, "打开文件", "./", "PDF(*.pdf)")
        if file:
            self.lineEdit.setText(str(file[0]))

    def pubshbutton_click(self):
        filename = self.lineEdit.text()
        password = self.lineEdit_2.text()
        if filename == "" or password == "":
            self.msg_box = QMessageBox(QMessageBox.Warning, "警告", "未输入密码或未选择文件")
        else:
            # 引用解密程序
            from pdf_jm import pdf_decrypt
            pdf_jm = pdf_decrypt(filename, password)
            if pdf_jm == 1:
                self.msg_box = QMessageBox(QMessageBox.Information, "提示", "文件解密成功，应在源文件目录下寻找", QMessageBox.Ok)
            elif pdf_jm == 2:
                self.msg_box = QMessageBox(QMessageBox.Warning, "警告",
                                           "密码错误或无法解密该文档！", QMessageBox.Ok)
            else:
                self.msg_box = QMessageBox(QMessageBox.Warning, "警告",
                                           "该文档非加密文档", QMessageBox.Ok)
        return self.msg_box.show()
